#!/bin/bash
source $DRAW_INI
source $DRAW_CFG

mkdir -p ../csv

NAME=$(basename $1)
RFILE="../csv/$NAME.indel.recal"
TFILE="../csv/$NAME.indel.tranches"


java -Xmx4g -jar $GATK \
  -T VariantRecalibrator \
  -R $REF_FASTA \
   --maxGaussians 4 -std 10.0 -percentBad 0.12 \
   -resource:mills,known=true,training=true,truth=true,prior=12.0 $BUNDLE_MILLS \
   -an QD -an FS -an ReadPosRankSum \
   -mode INDEL \
   -input $1.vcf \
   -recalFile $RFILE \
   -tranchesFile $TFILE
     
EXITSTATUS=$?
#   -an QD -an FS -an HaplotypeScore -an ReadPosRankSum -an InbreedingCoeff \


#force error when missing recalFile. Would prevent continutation of pipeline
if [[ ! -s "$RFILE" || ! -s "$TFILE" ]];
then
 echo "Missing $RFILE or $TFILE in ../csv" 
 exit 100
fi

exit $EXITSTATUS
